﻿// Write a program that compares two text files line by line 
// and prints the number of lines that are the same and the number of lines that are different. 
// Assume the files have equal number of lines.

using System;
using System.IO;

class CompareTextFiles
{
    static void Main()
    {
        string path = @"..\..\";
        string filename1 = "1.txt";
        string file1 = Path.Combine(path, filename1);
        string filename2 = "2.txt";
        string file2 = Path.Combine(path, filename2);

        try
        {
            int equalLinesCount = 0;
            string[] file1LinesArray = File.ReadAllLines(file1);
            string[] file2LinesArray = File.ReadAllLines(file2);
            int allLinesCount = file1LinesArray.Length;
            for (int l = 0; l < allLinesCount; l++)
            {
                if (file1LinesArray[l].Equals(file2LinesArray[l]))
                {
                    equalLinesCount++;
                }
            }

            Console.WriteLine("Compared file {0} and file {1}:", filename1, filename2);
            Console.WriteLine("All lines: {0}", allLinesCount);
            Console.WriteLine("Equals lines: {0}", equalLinesCount);
            Console.WriteLine("Different lines: {0}", allLinesCount - equalLinesCount);
        }
        catch (Exception exc)
        {
            Console.WriteLine(exc.Message);
        }
        catch
        {
            Console.WriteLine("Fatal error occurred.");
        }
    }
}